<!-- 物料信息项组件 -->
<script setup lang="jsx">
import { isEmpty } from 'lodash-es';
import { computed } from 'vue';
import { Empty } from 'ant-design-vue';

const simpleImage = Empty.PRESENTED_IMAGE_DEFAULT;

defineProps({
  infoList: {
    type: Array,
    default: () => []
  },
  labelWidth: {
    type: String,
    default: '79px'
  },
  title: {
    type: String,
    default: ''
  },
  titleColor: {
    type: String,
    default: '#646cff'
  },
  leftBackgroundColor: {
    type: String,
    default: 'rgba(126, 136, 254, 0.3)'
  }
});

const infoData = defineModel('infoData', { type: Object, default: () => ({}) });

const isNoData = computed(() => {
  return isEmpty(infoData.value);
});
</script>

<template>
  <div class="info-item h-full w-full">
    <div class="left" :style="{ backgroundColor: leftBackgroundColor }">
      <div>
        <div class="icon">
          <slot name="icon"></slot>
        </div>
        <div class="label w-full" :style="{ color: titleColor }">{{ title }}</div>
      </div>
    </div>
    <div class="info-data h-full">
      <template v-if="isNoData">
        <div class="h-full w-full flex-center">
          <AEmpty :image="simpleImage" :description="`暂无${title}`" />
        </div>
      </template>
      <template v-else>
        <div v-for="item in infoList" :key="item.key" class="info-data-item w-50%">
          <div class="label" :style="{ minWidth: labelWidth }">{{ item.title }}</div>
          <div class="value" :title="infoData[item.key]">
            {{ item.customRender ? item.customRender({ record: infoData }) : infoData[item.key] }}
          </div>
        </div>
      </template>
    </div>
  </div>
</template>

<style scoped lang="scss">
.info-item {
  border: 1px solid #aeaeae;
  border-radius: 8px;
  display: flex;
  align-items: center;
  padding: 15px;
  box-shadow: 4px 5px 10px rgba(0, 0, 0, 0.1);
  min-height: 276px;
  .left {
    width: 200px;
    height: 100%;
    border-radius: 3px;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    .icon {
      width: 100px;
      height: 100px;
      box-sizing: content-box;
      padding: 5px;
      background: #fff;
      border-radius: 50%;
      display: flex;
      justify-content: center;
      align-items: center;
    }
    .label {
      text-align: center;
      font-weight: bold;
      font-size: 18px;
      margin-top: 15px;
    }
  }

  .info-data {
    width: calc(100% - 200px);
    padding: 0 15px;
    display: flex;
    flex-wrap: wrap;
    .info-data-item {
      display: flex;
      align-items: center;
      font-size: 13px;
      width: calc(50% - 10px);
      flex-grow: 1;
      &:nth-child(2n) {
        margin-left: 10px;
      }
      .label {
        color: #aeaeae;
        font-weight: bold;
        width: 79px;
        text-align: justify;
        display: flex;
        justify-content: space-between;
        &::after {
          content: ':';
          margin: 0 5px;
        }
      }
      .value {
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
      }
    }
  }
}
</style>
